package com.cskaoyan.service.comment;

import com.cskaoyan.bean.MallCategoryExample;
import com.cskaoyan.bean.MallComment;
import com.cskaoyan.mapper.MallCommentMapper;
import com.cskaoyan.model.vo.comment.commentlist.WxCommentCountVo;
import com.cskaoyan.model.vo.comment.commentlist.WxCommentListData;
import com.cskaoyan.model.vo.comment.commentlist.WxCommentListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: project-market
 * @description:
 * @author: zhijie
 * @create: 2021-12-02 22:08
 **/
@Service
public class WxCommentServiceImpl implements WxCommentService {
    @Autowired
    MallCommentMapper mallCommentMapper;

    @Override
    public WxCommentListVo commentList(Integer valueId, Integer type, Integer limit, Integer page, Integer showType) {
        PageHelper.startPage(page, limit);
        List<WxCommentListData> vo = mallCommentMapper.commentList(valueId, type, showType);
        PageInfo<WxCommentListData> info = new PageInfo<>(vo);
        WxCommentListVo wxCommentListVo = new WxCommentListVo();
        wxCommentListVo.setLimit(limit);
        wxCommentListVo.setPage(page);
        wxCommentListVo.setPages(info.getPages());
        wxCommentListVo.setTotal(info.getTotal());
        wxCommentListVo.setList(vo);
            return wxCommentListVo;
    }

    @Override
    public WxCommentCountVo commentCount(Integer valueId, Integer type) {
        int allCount = mallCommentMapper.countCommentByValueId(valueId, type);
        int hasPicCount = mallCommentMapper.countCommentHasPicByValueId(valueId, type);
        WxCommentCountVo vo = new WxCommentCountVo();
        vo.setAllCount(allCount);
        vo.setHasPicCount(hasPicCount);
        return vo;
    }

    @Override
    public MallComment commentPost(MallComment mallComment, Integer userId) {
        mallComment.setUserId(userId);
        mallComment.setAddTime(new Date());
        mallComment.setUpdateTime(new Date());
      mallCommentMapper.insertSelective(mallComment);
        return mallComment;
    }
}
